package edu.hawaii.duedates.tests;

import static org.junit.Assert.assertEquals;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.junit.Test;

import edu.hawaii.duedates.Book;
import edu.hawaii.duedates.User;

/**
 * Test case for Book methods.
 * @author Vincent Leung
 *
 */

public class TestBook {

  private static final String title = "Alice in WonderLand";
  private static final String title2 = "Mother Goose";
  private static final String duedate = "11/12/2008";
  private static final String duedate2 = "01/01/2009";
  private static final String dateFormat = "MM/dd/yy";

/**
 * Test Book Method.
 * 
 * @throws ParseException when parsing.
 */ 
  @Test 
  public void testCreateBook() throws ParseException {
    SimpleDateFormat formattedDate = new SimpleDateFormat(dateFormat, Locale.US);
    Date due = formattedDate.parse(duedate);
    Book book = new Book (title, due);
    assertEquals("Testing Title", title, book.getTitle());
    assertEquals("Testing DueDate", due, book.getDuedate());    
  }

/**
 * Test CompareTo Method.
 * 
 * @throws ParseException when parsing.
 */
  @Test
  public void testCompare() throws ParseException {
    SimpleDateFormat formattedDate = new SimpleDateFormat(dateFormat, Locale.US);
    Date due = formattedDate.parse(duedate);
    Book book = new Book (title, due); 
    assertEquals("Testing CompareTo", 0, book.compareTo(book));
  }
  
/**
 * Test equals Method.
 * 
 * @throws ParseException when parsing.
 */
  @Test
  public void testEqual() throws ParseException {
    SimpleDateFormat formattedDate = new SimpleDateFormat(dateFormat, Locale.US);
    Date due = formattedDate.parse(duedate);
    Book book = new Book (title, due); 
    due = formattedDate.parse(duedate2);
    Book book2 = new Book (title2, due);
    User user = new User("Vince", "123");
    assertEquals("Testing Equal 1", true, book.equals(book));
    assertEquals("Testing Equal 2", false, book.equals(book2));
    assertEquals("Testing Equal 3", false, book.equals(user));
  }
  
/*
 * Test hashCode Method  
 *
 * @Test
 *  public void TestHashCode() throws ParseException {
 *   String dateFormat = "MM/dd/yy";
 *   SimpleDateFormat formattedDate = new SimpleDateFormat(dateFormat, Locale.US);
 *   Date due = formattedDate.parse(duedate);
 *   Book book = new Book (title, due); 
 *   assertEquals("Testing hashCode", "-1022305122", book.hashCode());
 * }
 */
/**
 * Test toString method.
 * 
 * @throws ParseException when parsing.
 */
  @Test
  public void testToString() throws ParseException {
    SimpleDateFormat formattedDate = new SimpleDateFormat(dateFormat, Locale.US);
    Date due = formattedDate.parse(duedate);
    Book book = new Book (title, due); 
    assertEquals("Testing toString", 
      "Info: Alice in WonderLand\nStatus: Wed Nov 12 00:00:00 HST 2008", book.toString());  
  }
}